#include <stdio.h>
#include <stdlib.h>

struct Node {
    int val;
    struct Node *next;
};

struct Node *__reverseList(struct Node *head, struct Node *tail) {
    struct Node *cur = head;
    struct Node *prev = tail->next;
    struct Node *nxt = head;
    while (cur) {
        // printf("[%d][%p]   |   [%p]   | [%d]\n", cur->val, cur, tail->next, (int)(cur == tail->next));
        nxt = cur->next;
        cur->next = prev;
        prev = cur;

        if (cur == tail)
            break;
        else
            cur = nxt;
    }
    return tail;
}

struct Node *reverseList(struct Node *head, int m, int n) {
    struct Node *prev = head;
    struct Node *to = head;
    for (int i = 0; i < m - 2; i++) prev = prev->next;
    for (int i = 0; i < n - 1; i++) to = to->next;
    if (m == 1)
        return __reverseList(head, to);
    else {
        prev->next = __reverseList(prev->next, to);
        return head;
    }
}

struct Node *createList(int *nums, int n) {
    struct Node *head = NULL;
    struct Node *tail = NULL;
    for (int i = 0; i < n; i++) {
        struct Node *node = (struct Node *)malloc(sizeof(struct Node));
        node->val = nums[i];
        if (head == NULL)
            head = node;
        else
            tail->next = node;
        tail = node;
    }
    tail->next = NULL;
    return head;
}

void printList(struct Node *head) {
    while (head != NULL) {
        printf("%d->", head->val);
        head = head->next;
    }
    printf("NULL\n");
}

int main() {
    int A[1010], len = 0;
    char c = ' ';
    while (c != '\n') {
        scanf("%d%c", &A[len++], &c);
    }
    struct Node *head = createList(A, len);
    printList(head);
    int m, n;
    scanf("%d%d", &m, &n);

    printList(reverseList(head, m, n));
}